package com.wubotao.multithreading;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockTest {
	private Lock lock = new ReentrantLock();// 锁对象

	public void output(String name) {
		lock.lock(); // 得到锁

		try {
			for (int i = 0; i < name.length(); i++) {
				System.out.print(name.charAt(i));
			}
		} finally {
			lock.unlock();// 释放锁
		}
	}

	public static void main(String[] args) {
		new LockTest().output("test");
	}
}
